layui.use(['form', 'layer', 'laydate'], function () {
    var form = layui.form
    layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        company_id = sessionStorage["company_id"];
    laydate.render({
        elem: '.validYear',
        format: 'yyyy年MM月',
        type: 'month'
    });
    setTimeout(function () {
        form.render('select')
    }, 500)
    form.on("submit(editProject)", function (data) {
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });
        const { projectId: id, eductionType: type, companyName: rid, projectName: produ, projectDetail: produIntroduce, price, agencyPrice, externalPrice, remarks, validYear } = data.field;
        var project = {
            id,
            type,
            rid,
            produ,
            produIntroduce,
            price,
            agencyPrice,
            externalPrice,
            remarks,
            validYear,
            time: getTime(),
            company_id
        }
        if (data.field.addOrUpdate == 0) {//添加
            $.ajax({
                url: baseUrl + "project_info/addProject.php",
                data: project,
                type: "GET",
                dataType: "text",
                success: function (data) {
                    console.log(data);
                    if (data == "1") {
                        message(index, '添加项目信息成功！')
                    } else {
                        message(index, '添加项目信息失败！')
                    }
                }
            })
        } else {//修改
            $.ajax({
                url: baseUrl + "project_info/updateProject.php",
                data: project,
                type: "GET",
                dataType: "text",
                success: function (data) {
                    if (data == "1") {
                        message(index, '修改项目信息成功！')
                    } else {
                        message(index, '修改项目信息失败！')
                    }
                }
            })
        }
        return false;
    })
    function message(index, msg) {
        setTimeout(function () {
            top.layer.close(index);
            top.layer.msg(msg);
            parent.layer.closeAll("iframe");
            //父页面表格重载
            parent.layui.table.reload("projectListTable");
        }, 1000);
    }
})